package data_structure;

public class leetcode_0092 {
    public ListNode reverseBetween(ListNode head, int left, int right) {
        reverse(head,left,right);
        return head;
    }
    public void reverse(ListNode head,int left,int right){
        if(left>=right) return;
        ListNode p=head;
        ListNode q=head;
        for(int i=0;i<right-left;++i){
            q=q.next;
        }
        for(int i=0;i<left-1;++i){
            p=p.next;q=q.next;
        }
        int tem=q.val;
        q.val=p.val;
        p.val=tem;
        p=head;q=head;
        reverse(head,left+1,right-1);
    }
}
